﻿using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Ordering.Application.PipelineBehavior;
using Ordering.Infrastructure;

namespace Ordering.Application
{
    public static class AppServiceCollectionExtensions
    {
        public static void AddApplicationServices(this IServiceCollection services)
        {
            services.RegisterInjectionServices<OrderingDbContext>();
            services.AddMediatR(c =>
            {
                c.Lifetime = ServiceLifetime.Scoped;
                c.AddBehavior(
                    typeof(IPipelineBehavior<,>),
                    typeof(TransactionBehavior<,>),
                    ServiceLifetime.Scoped);
                c.RegisterServicesFromAssembly(typeof(AppServiceCollectionExtensions).Assembly);
            });
        }
    }
}
